<?php

require_once("../core/init.php");

$Gepard->signal(_SIG_INIT);
$user = $Gepard->user->GetUserID();
$group = $Gepard->user->GetUserGroup();

if ( $user!=0 && $group==_GROUP_ADMIN ){
		header("location:index.php");
 } else {
	
	if( isset($_SERVER['PHP_AUTH_USER']) ) {
		$user = $_SERVER["PHP_AUTH_USER"];
		$password = $_SERVER["PHP_AUTH_PW"];
		$user = $Gepard->escapeString($user);		
		if( $Gepard->user->sysauth($user,$password) ){
			header("location:index.php");
		} else {
			form("Your login or password is incorrect, please, try again.");
		}
	} else {
			form("Welcome, please enter your login and password");
	}
}
function form($message){
		header('WWW-Authenticate: Basic realm="'.$message);
		header('HTTP/1.0 401 Unauthorized');
		print 'Aborted.';
}